package com.flowable.controller;

import com.alibaba.fastjson.JSONObject;
import com.flowable.common.result.CommonResult;
import com.flowable.pojo.ProcessModel;
import com.flowable.service.ProcModelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

/**
 * 流程模型 控制器
 */
@RestController
@RequestMapping("/model")
public class ProcModelController {

    @Autowired
    private ProcModelService procModelService;

    /**
     * 转为bpmn.xml，并预览
     *
     * @param processModel json格式
     * @throws IOException
     */
    @PostMapping("/json2bpmnxmlAndView")
    public void json2bpmnxmlAndView(@RequestBody ProcessModel processModel) throws IOException {
        procModelService.json2bpmnxmlAndView(processModel);
    }

    /**
     * 转为bpmn.xml，并上传到/resources目录下
     *
     * @param processModel
     * @return
     */
    @PostMapping("/json2bpmnxmlAndUpload")
    public CommonResult json2bpmnxmlAndUpload(@RequestBody ProcessModel processModel) {
        return procModelService.json2bpmnxmlAndUpload(processModel);
    }
}
